package com.hyfrogx.modules.app.service.impl;

import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil;
import com.hyfrogx.common.utils.R;
import com.hyfrogx.modules.app.service.WeChatService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Date;

/**
 * TODO 微信接口 实现类
 *
 * @author wanglei
 * @version 1.0.0
 * @createdate 2019/03/13
 */
@Service("weChatService")
@Slf4j
public class WeChatServiceImpl implements WeChatService {

	@Override
	@Transactional(rollbackFor = Exception.class)
	public R payBack(String old, Integer payType, String endTime, String transactionId, String totalFee, boolean isSendMsg) {
		if (ObjectUtil.isNull(old)) {
			return R.error("当前环境未找到该订单");
		}
		log.info("---------------------查询到订单：" + old.toString());

		Date payTime = null;
		if (StrUtil.isNotEmpty(endTime)) {
			try {
				payTime = DateUtil.parse(endTime, "yyyyMMddHHmmss");
			} catch (Exception e) {
				log.info("订单支付时间转换异常：" + e.getMessage());
				payTime = new Date();
			}
		} else {
			payTime = new Date();
		}
			return R.ok();
	}


}
